package com.aysf.drafter.controller;

import com.aysf.drafter.entity.*;
import com.aysf.drafter.service.ICustomersService;
import com.aysf.drafter.service.INursingRecordsService;
import com.aysf.drafter.service.INursingStaffService;
import com.aysf.drafter.service.INursingTypesService;
import com.aysf.drafter.vo.NursingVO;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author MaoZz
 * @since 2024-12-26 15:34:01
 */
@RestController
@CrossOrigin
@RequestMapping("/nursingrecords")
public class NursingrecordsController {
    @Autowired
    private INursingRecordsService nursingRecordsService;
    @Autowired
    private INursingTypesService nursingTypesService;
    @Autowired
    private INursingStaffService nursingStaffService;
    @Autowired
    private ICustomersService customersService;


    @RequestMapping("/getAll")
    public Result getAll(Integer current,Integer size) {
        Page<NursingRecords> Page = new Page<>(current, size);
        QueryWrapper<NursingRecords> recordId = new QueryWrapper<NursingRecords>()
                .orderByAsc("record_id");
        Page<NursingRecords> page =
                nursingRecordsService.page(Page, recordId);
        ArrayList<NursingVO> nursingVOS = new ArrayList<>();
        for (NursingRecords nursingRecords : page.getRecords()) {
            NursingVO nursingVO = new NursingVO();
            nursingVO.setRecordId(nursingRecords.getRecordId());
            nursingVO.setTotal((int) page.getTotal());
            nursingVO.setAge(customersService
                    .getOne(new QueryWrapper<Customers>()
                            .eq("customer_id", nursingRecords.getCustomerId())).getAge());
            nursingVO.setName(customersService
                    .getOne(new QueryWrapper<Customers>()
                            .eq("customer_id", nursingRecords.getCustomerId())).getName());
            nursingVO.setGender(customersService
                    .getOne(new QueryWrapper<Customers>()
                            .eq("customer_id", nursingRecords.getCustomerId())).getGender());
            nursingVO.setNursingDate(nursingRecords.getNursingDate());
            nursingVO.setTypeName(nursingTypesService.getOne(new QueryWrapper<NursingTypes>()
                    .eq("nursing_type_id", nursingRecords.getNursingTypeId())).getTypeName());
            nursingVO.setNursingName(nursingStaffService.getOne(new QueryWrapper<NursingStaff>()
                    .eq("staff_id", nursingRecords.getStaffId())).getNursingName());
            nursingVOS.add(nursingVO);

        }
        if (nursingVOS.size() > 0) {
            return new Result("success", nursingVOS);
        } else return new Result("error");


    }


    @RequestMapping("/update")
    public Result update(Integer id) {
        System.out.println(id);
        NursingRecords byId = nursingRecordsService.getById(id);
        //把所有护工医生返回  和名字返回
        HashMap<String, List<NursingStaff>> map = new HashMap<>();
        List<NursingStaff> list = nursingStaffService.list();


        map.put("nursing",list);



        return new Result("success", map);
//        else return new Result("error");
    }


}
